package com.hspedu.spring.factory;

import com.hspedu.spring.bean.Monster;
import org.springframework.beans.factory.FactoryBean;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Charlie
 * @version 1.0
 * @date 1/11/2025 下午9:43
 */
public class MyFactoryBean implements FactoryBean<Monster> {
    private String key;
    private Map<String, Monster> monster_map;

    {
        monster_map = new HashMap<>();
        monster_map.put("monster01", new Monster("niu", 100, "芭蕉扇"));
        monster_map.put("monster02", new Monster("niu2", 101, "芭蕉扇~"));
    }

    public void setKey(String key) {
        this.key = key;
    }

    @Override
    public Monster getObject() throws Exception {
        return monster_map.get(key);
    }

    @Override
    public Class<?> getObjectType() {
        return Monster.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
